package com.igeek.oo;

import java.util.Objects;

/**
 *  继承：所有类的超类Object
 *        提供了很多的方法，可以供我们使用，同时还可以重写他的方法
 *        一个完整的实例对象：
 *          1.封装的属性
 *          2.无参的构造函数
 *          3.有参的构造函数
 *          4.重写Object 的toString() equals()
 */
public class Person {

    private int age;

    private double height;

    private String name;

    private String address;

    private String idNo;

    private Animal animal;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if(age > 0){
            this.age = age;
        }
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getIdNo() {
        return idNo;
    }

    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }

    public Animal getAnimal() {
        return animal;
    }

    public void setAnimal(Animal animal) {
        this.animal = animal;
    }

    public Person() {
    }

    public Person(int age, double height, String name, String address, String idNo) {
        this.age = age;
        this.height = height;
        this.name = name;
        this.address = address;
        this.idNo = idNo;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", height=" + height +
                ", name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", idNo='" + idNo + '\'' +
                '}';
    }


    /**
     * 手动实现重写equals方法
     * @param o
     * @return
     */
    public boolean equals(Object o){
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;

        if(person.idNo.equals(this.idNo)){
            return true;
        }else {
            return false;
        }
    }

}

/**
 * 多态的实现:
 *  体现了代码的灵活性，用一个父类就可以包容更多的子类，还可以实现代码的复用性
 */
class PersonTest{

    public static void main(String[] args) {

        Person tom = new Person(10,160,"tom","北京","12222222222222222");

        //养宠物
        tom.setAnimal(new Dog());

        Person jack = new Person(11,161,"jack","上海","128888888888888888");

        //养宠物
        jack.setAnimal(new Cat());
    }
}
